package Clothing.controller.clothing;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import Clothing.bean.BaseResponse;
import Clothing.bean.request.clothing.AddClothingRequest;
import Clothing.bean.request.clothing.DeleteClothingRequest;
import Clothing.bean.request.clothing.GetClothingListRequest;
import Clothing.bean.respose.clothing.GetClothingListResponse;
import Clothing.service.clothing.ClothingService;
import Clothing.util.ResultModel;

@Controller
@RequestMapping(value = "/Clothing")
public class ClothingController {

    @Resource
    private ClothingService clothingService;
    
    
    @ResponseBody
    @RequestMapping(value = "/getClothingList" ,method = RequestMethod.POST)
    public ResultModel getClothingList(@RequestBody GetClothingListRequest request){
        ResultModel resultModel = new ResultModel();
        GetClothingListResponse response = new GetClothingListResponse();
        int result = clothingService.getClothingList(request,response);
        switch (result) {
            case 0:
                response.setSuccess("0");
                break;
            case 1:
                response.setSuccess("1");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
    @ResponseBody
    @RequestMapping(value = "/addClothing" ,method = RequestMethod.POST)
    public ResultModel addClothing(@RequestBody AddClothingRequest request){
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        int result = clothingService.addClothing(request);
        switch (result) {
            case 0:
                response.setSuccess("1");
                break;
            case 1:
                response.setSuccess("0");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
    @ResponseBody
    @RequestMapping(value = "/deleteClothing" ,method = RequestMethod.POST)
    public ResultModel deleteClothing(@RequestBody DeleteClothingRequest request){
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        int result = clothingService.deleteClothing(request);
        switch (result) {
            case 0:
                response.setSuccess("1");
                break;
            case 1:
                response.setSuccess("0");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
    @ResponseBody
    @RequestMapping(value = "/editClothing" ,method = RequestMethod.POST)
    public ResultModel editClothing(@RequestBody AddClothingRequest request){
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        int result = clothingService.editClothing(request);
        switch (result) {
            case 0:
                response.setSuccess("1");
                break;
            case 1:
                response.setSuccess("0");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
}
